//
//  HMComposeButton.swift
//  Weibo
//
//  Created by teacher on 2017/6/11.
//  Copyright © 2017年 teacher. All rights reserved.
//

import UIKit
//  自定义菜单按钮
class HMComposeButton: UIButton {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        titleLabel?.textAlignment = .center
        //  居中显示
        imageView?.contentMode = .center
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //  子控件布局调整
    override func layoutSubviews() {
        super.layoutSubviews()
        //  如果执行transform动画不能使用frame，因为frame发生了改变，而bounds不会改变
        imageView?.frame.size.width = self.bounds.size.width
        imageView?.frame.size.height = self.bounds.size.width
        imageView?.frame.origin.y = 0
        
        titleLabel?.frame.origin.y = self.bounds.size.width
        titleLabel?.frame.origin.x = 0
        titleLabel?.frame.size.width = self.bounds.size.width
        titleLabel?.frame.size.height = self.bounds.size.height - self.bounds.size.width
    }

}
